package xyz.caijiwang.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.http.converter.BufferedImageHttpMessageConverter;
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import xyz.caijiwang.response.JsonHttpMessageConverter;


import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

@Configuration
public class ResponseConfig {

    @Bean
    public StringHttpMessageConverter stringHttpMessageConverter() {
        return new StringHttpMessageConverter();
    }

    @Bean
    public ByteArrayHttpMessageConverter byteArrayHttpMessageConverter() {
        return new ByteArrayHttpMessageConverter();
    }

    @Bean
    public BufferedImageHttpMessageConverter bufferedImageHttpMessageConverter() {
        return new BufferedImageHttpMessageConverter();
    }

    @Bean
    public JsonHttpMessageConverter fastJsonHttpMessageConverter() {
        JsonHttpMessageConverter bean = new JsonHttpMessageConverter();
        List<MediaType> lists = new ArrayList<>();
        lists.add(MediaType.APPLICATION_JSON);
        lists.add(MediaType.TEXT_HTML);
        bean.setDefaultCharset(StandardCharsets.UTF_8);
        bean.setSupportedMediaTypes(lists);
        return bean;
    }
}
